package common

import (
	"github.com/go-redis/redis"
	"github.com/spf13/viper"
	"kuukaa.fun/danmu-v4/util"
)

var RedisClient *redis.Client

func Redis() {
	client := redis.NewClient(&redis.Options{
		Addr:     viper.GetString("redis.address"),
		Password: viper.GetString("redis.password"),
		DB:       0, // use default DB
	})
	_, err := client.Ping().Result()
	if err != nil {
		util.Logfile(util.ErrorLog, " redis error "+err.Error())
		RedisClient = nil
	} else {
		RedisClient = client
	}
}
